package Java7_Concurrency_Cookbook.concurrent_custom.custom_executor_use_custom_thread_factory;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * <b>在Executor对象中使用ThreadFactory</b><br/>
 * 本示例中, 创建Executor对象时传入了自定义的ThreadFactory<br/>
 * Executor将使用MyThreadFactory创建的线程(MyThread)来执行任务(MyTask)<br/>
 * MyThread.run()中会调用MyTask.run()方法
 * @author lixiangke
 * @date 2017/11/24
 */
public class Main {
    public static void main(String[] args) throws InterruptedException {
        MyThreadFactory myThreadFactory = new MyThreadFactory("MyThreadFactory");
        ExecutorService executor = Executors.newCachedThreadPool(myThreadFactory);
        MyTask myTask = new MyTask();
        executor.submit(myTask);
        executor.shutdown();
        executor.awaitTermination(1, TimeUnit.DAYS);
        System.out.println("Main: End of the program");
    }
}
